package flc.ast.fragment;

import androidx.fragment.app.Fragment;

import android.view.View;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import flc.ast.R;
import flc.ast.activity.DrawActivity;
import flc.ast.activity.RecordActivity;
import flc.ast.activity.MyActivity;
import flc.ast.databinding.FragmentHomeBinding;
import flc.ast.utils.Content;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link HomeFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HomeFragment extends BaseNoModelFragment<FragmentHomeBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);
        mDataBinding.rlMy.setOnClickListener(this);
        mDataBinding.ivRecord.setOnClickListener(this);
        mDataBinding.ivNewDraw.setOnClickListener(this);
        mDataBinding.ivDraw1.setOnClickListener(this);
        mDataBinding.ivDraw2.setOnClickListener(this);
        mDataBinding.ivDraw3.setOnClickListener(this);
        mDataBinding.ivDraw4.setOnClickListener(this);
        mDataBinding.ivDraw5.setOnClickListener(this);
        mDataBinding.ivDraw6.setOnClickListener(this);
        mDataBinding.ivDraw7.setOnClickListener(this);
        mDataBinding.ivDraw8.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.rlMy://个人中心
                startActivity(MyActivity.class);
                break;
            case R.id.ivRecord://历史记录
                RecordActivity.sFilePath= Content.MyHomeRecord;
                startActivity(RecordActivity.class);
                break;
            case R.id.ivNewDraw:
                DrawActivity.isNew = true;
                DrawActivity.type=0;
                startActivity(DrawActivity.class);
                break;
            case R.id.ivDraw1:
                DrawActivity.isNew = false;
                DrawActivity.type=0;
                DrawActivity.img = R.drawable.aa1;
                DrawActivity.imgBg = R.drawable.a1;
                startActivity(DrawActivity.class);
                break;
            case R.id.ivDraw2:
                DrawActivity.isNew = false;
                DrawActivity.type=0;
                DrawActivity.img = R.drawable.aa2;
                DrawActivity.imgBg = R.drawable.a2;
                startActivity(DrawActivity.class);
                break;
            case R.id.ivDraw3:
                DrawActivity.isNew = false;
                DrawActivity.type=0;
                DrawActivity.img = R.drawable.aa3;
                DrawActivity.imgBg = R.drawable.a3;
                startActivity(DrawActivity.class);
                break;
            case R.id.ivDraw4:
                DrawActivity.isNew = false;
                DrawActivity.type=0;
                DrawActivity.img = R.drawable.aa4;
                DrawActivity.imgBg = R.drawable.a4;
                startActivity(DrawActivity.class);
                break;
            case R.id.ivDraw5:
                DrawActivity.isNew = false;
                DrawActivity.type=0;
                DrawActivity.img = R.drawable.aa5;
                DrawActivity.imgBg = R.drawable.a5;
                startActivity(DrawActivity.class);
                break;
            case R.id.ivDraw6:
                DrawActivity.isNew = false;
                DrawActivity.type=0;
                DrawActivity.img = R.drawable.aa6;
                DrawActivity.imgBg = R.drawable.a6;
                startActivity(DrawActivity.class);
                break;
            case R.id.ivDraw7:
                DrawActivity.isNew = false;
                DrawActivity.type=0;
                DrawActivity.img = R.drawable.aa7;
                DrawActivity.imgBg = R.drawable.a7;
                startActivity(DrawActivity.class);
                break;
            case R.id.ivDraw8:
                DrawActivity.isNew = false;
                DrawActivity.type=0;
                DrawActivity.img = R.drawable.aa8;
                DrawActivity.imgBg = R.drawable.a8;
                startActivity(DrawActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        Date date = new Date();
        String pattern = "HH";
        Locale locale = Locale.getDefault();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, locale);
        String time = simpleDateFormat.format(date);
        int hour = Integer.parseInt(time);
        if (hour >= 0 && hour <= 5) {
            mDataBinding.tvTime.setText(getString(R.string.home_text4));
        }
        if (hour > 5 && hour <= 12) {
            mDataBinding.tvTime.setText(getString(R.string.home_text1));
        }
        if (hour > 12 && hour <= 13) {
            mDataBinding.tvTime.setText(getString(R.string.home_text2));
        }
        if (hour > 13 && hour <= 18) {
            mDataBinding.tvTime.setText(getString(R.string.home_text3));
        }
        if (hour > 18 && hour <= 24) {
            mDataBinding.tvTime.setText(getString(R.string.home_text4));
        }
    }
}